package com.briup.web.servlet;

import com.briup.bean.Book;
import com.briup.service.IBookService;
import com.briup.service.impl.BookServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

/**
 * 书籍详情：点击超链接书籍跳转bookID
 */
@WebServlet(name = "BookServlet", value = "/bookInfo")
public class BookServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        IBookService bookService = new BookServiceImpl();

        //1、接收参数
        Integer bookId = Integer.valueOf(request.getParameter("bookId"));
//        System.out.println("接收到的bookId为" + bookId);

        //2、调用service层方法
        Book book = bookService.findBookById(bookId);

        //存入session
        HttpSession session = request.getSession();
        session.setAttribute("bookInfo", book);

        //跳转并显示 书籍详情页面
        response.sendRedirect("/viewBook.jsp");  //书籍详情

    }
}
